package com.ptswitch.material.model.common;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.validation.constraints.Size;

import org.hibernate.validator.constraints.Email;

@Entity(name = "mstar_uzer")
public class Uzer extends org.hxzon.project.model.Uzer {
    public static final int Power_Admin = 0;
    public static final int Power_Admins = 1;
    public static final int Power_Normal = 2;
    public static final int Power_Guest = 9;

    public static final int Department_None = 0;
    public static final int Department_Financial = 1;
    public static final int Department_Buyer = 2;
    public static final int Department_Production = 3;
    public static final int Department_Hardware = 4;
    public static final int Department_Software = 5;
    public static final int Department_ContractAuditor = 6;

    private static final long serialVersionUID = 7570429986649512051L;

    @Column(columnDefinition = DefineVarchar2048)
    @Size(max = DefineSize2048)
    private String uzerRoles;

    @Column(columnDefinition = DefineVarchar2048)
    @Size(max = DefineSize2048)
    // @NotBlank
    @Email
    private String email;

    @Column(length = 2)
    private int department = Department_None;

    @Column(length = 2)
    private int adminGrade = Power_Guest;

    public String getUzerRoles() {
        return uzerRoles;
    }

    public void setUzerRoles(String uzerRoles) {
        this.uzerRoles = uzerRoles;
    }

    public String getEmail() {
        return email;
    }

    public void setEmail(String email) {
        this.email = email;
    }

    public int getDepartment() {
        return department;
    }

    public void setDepartment(int department) {
        this.department = department;
    }

    public int getAdminGrade() {
        return adminGrade;
    }

    public void setAdminGrade(int adminGrade) {
        this.adminGrade = adminGrade;
    }

    public String toString() {
        return this.getRealname() + "(" + this.getUsername() + "," + this.adminGrade + ")";
    }

    public boolean hasRole(String rolename) {
        return this.getUzerRoles().contains(";" + rolename + ";");
    }
}
